package com.aps.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.aps.entity.ResultEntity;
import com.aps.entity.domain.device.DeviceCenter;
import com.aps.page.BaseQuery;
import com.aps.service.IDeviceCenterService;
import com.aps.service.rep.DeviceTypeRep;
import com.aps.service.rep.StoreReq;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * @author liaoguangan
 * @description <>
 * @date 2018/4/5 22:56
 */
@RestController
@RequestMapping("/manage-api")
@Api(value = "manage-device-api", description = "设备管理接口")
public class DeviceApi {

    @Autowired
    private StoreReq storeReq;

    @Autowired
    private DeviceTypeRep deviceTypeRep;

    @Autowired
    private IDeviceCenterService deviceCenterService;

    //////////////////设备相关////////////////////////////////

    @RequestMapping(value = "/device", method = RequestMethod.POST)
    @ApiOperation("保存设备信息")
    public ResultEntity device(@RequestBody DeviceCenter deviceCenter) {
        return new ResultEntity(deviceCenterService.add(deviceCenter));
    }

    @RequestMapping(value = "/list-device", method = RequestMethod.POST)
    @ApiOperation("查询设备列表信息")
    public ResultEntity listDevice(@RequestBody BaseQuery baseQuery) {
        return new ResultEntity(deviceCenterService.listDevice(baseQuery));
    }

    @RequestMapping(value = "/device/{id}", method = RequestMethod.GET)
    @ApiOperation("查询设备信息")
    public ResultEntity get(@PathVariable("id") String id) {
        return new ResultEntity(deviceCenterService.get(id));
    }

    @RequestMapping(value = "/device/{id}", method = RequestMethod.DELETE)
    @ApiOperation("删除设备信息")
    public ResultEntity deleteDevice(@PathVariable("id") String id) {
        deviceCenterService.delete(id);
        return new ResultEntity(true);
    }

    @RequestMapping(value = "/store", method = RequestMethod.GET)
    @ApiOperation("获取门店信息")
    public ResultEntity store() {
        return new ResultEntity(storeReq.findAll());
    }

    @RequestMapping(value = "/device-type", method = RequestMethod.GET)
    @ApiOperation("获取设备类型信息")
    public ResultEntity deviceType() {
        return new ResultEntity(deviceTypeRep.findAll());
    }

}
